package net.litxuf.Util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegUtil 
{
	private static Pattern emailPattern=Pattern.compile("[\\w.]+@(\\w+.)+[a-zA-Z]{2,3}");
	
	private static Pattern userPattern=Pattern.compile("[0-9a-zA-Z._\\u4e00-\\u9fa5]{3,}");
	
	private static Pattern mobilePattern=Pattern.compile("(^15|^13)\\d{9}");
	private static Pattern posPattern=Pattern.compile("[\\d]{6}");
	private static Pattern telPattern=Pattern.compile("[\\d\\-]*");
	
	
	private static String[] allowExtnames = { ".gif", ".jpg", ".png", ".bmp" };
	private static String[] allowdExtnames = { ".rar", ".txt", ".doc", ".zip"};
	
	private static Pattern passwordPattern=Pattern.compile("[0-9a-zA-Z]{6,20}");
	
	public static boolean isPassword(String input)
	{
		if(input==null) return false;
		Matcher matcher=passwordPattern.matcher(input);
		return matcher.matches();
	}
	public static boolean isMail(String input)
	{
		if(input==null) return false;
		Matcher matcher=emailPattern.matcher(input);
		return matcher.matches();
	}

	public static boolean isUser(String input)
	{
		if(input==null) return false;
		Matcher matcher=userPattern.matcher(input);
		return matcher.matches();
		
	}

	public static boolean isImage(String img) {
		if (img == null)
			return false;
		for (int i = 0; i<allowExtnames.length; i++) {
			if (img.toLowerCase().endsWith(allowExtnames[i]))
				return true;
		}
		return false;
	}
	
	public static boolean isFile(String img) {
		if (img == null)
			return false;
		for (int i = 0; i<allowdExtnames.length; i++) {
			if (img.toLowerCase().endsWith(allowdExtnames[i]))
				return true;
		}
		return false;
	}
	
	public static boolean isTelNum(String tel){
		if(tel==null) return false;
		Matcher matcher=telPattern.matcher(tel);
		return matcher.matches();
	}
	
	
	public static boolean isMobile(String tel){
		if(tel==null) return false;
		Matcher matcher=mobilePattern.matcher(tel);
		return matcher.matches();
	}
	
	public static boolean isPos(String tel){
		if(tel==null) return false;
		Matcher matcher=posPattern.matcher(tel);
		return matcher.matches();
	}
	
	
	public static void main(String[] args) {
		String s="litx_u.f@163.com";
		if(isMail(s))System.out.print("yes");
	}
}
